<!--
 * @Author: 'yangyuhang1203' '2621131059@qq.com'
 * @Date: 2025-09-09 09:45:32
 * @LastEditors: 'yangyuhang1203' '2621131059@qq.com'
 * @LastEditTime: 2025-09-09 09:56:49
 * @FilePath: \企业级\前端\js\js变量.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>js变量</title>
</head>
<body>
    <script>
        //变量声明
        var i = 1;
        var s = '字符串';
        var d = 2.0;
        var b = true;
        var arr = [1,2,3,4];
        var stu = {
            name:'张三',
            age:18,
            gender:'男'
        }; //json格式
        var n = null;//空值
        var u = undefined;//未定义

        {
            //框住了作用域，外部访问不到
            var i1=3; //全局
            //let i2 = 4; //局部,不能重复声明
        }
        console.log(i1);
        //console.log(i2);//报错,Uncaught ReferenceError: i2 is not defined
        //常量
        const PI = 3.14;
        console.log(PI);

    </script>
</body>
</html>